home *** CD-ROM | disk | FTP | other *** search
- <?php
- /* album.php - version 2
- * .net magazine (www.netmag.co.uk), issue 83
- * Matt Kynaston, 2001
- * Distributed under the GNU Public License - www.gnu.org/copyleft/gpl.html
- *
- * This version of the PHP Photo Album dynamically creates thumbnails from the files
- * uploaded to the 'photos' directory. It gives the user the opportunity to upload
- * their own photos to the album. It requires thumbnail.php to be in the same
- * directory as it.
- *
- * Also requires PHP4 with the GD and ZLIB extensions installed (php_gd.dll and
- * php_zlib.dll on Windows). These are available from the full download of PHP at
- * www.php.net. Modify your php.ini file (C:\WINDOWS\PHP.INI in Windows systems) to
- * point at them.
- */
- ?>
- <html>
- <head>
- <title>Photo Album</title>
- </head>
-
- <body bgcolor="#FFFFFF" text="#000000">
- <h1>PHP Photo Album</h1>
- <h3>(slow version)</h3>
-
- <?php
- // if file has been posted, copy to photo directory
- if (isset($ulFile) && $ulFile_name) {
- if (copy($ulFile, "photos/$ulFile_name")) {
- print "<p>$ulFile_name successfully uploaded</p>\n";
- } else {
- print "<p>Oops! Couldn't upload $ulFile_name</p>\n";
- }
- unlink($ulFile);
- }
- ?>
-
-
- <form name="form1" method="post" action="<?php print $PHP_SELF?>" enctype="multipart/form-data">
- <p>Add your own image to the album:<br>
- <input type="file" name="ulFile">
- </p>
- <p>
- <input type="submit" name="Submit" value="Submit">
- </p>
- </form>
-
- <p> </p>
- <table width="100%" border="0" cellspacing="10">
- <tr align="center">
- <?php
- // this section generates table rows filled with images
- $num_cols = 4;
- $dirname = "photos";
-
- $col = 0;
- $dh = opendir( $dirname ); // open directory for reading
-
- // loop through all files in photo directory, reading filename into $file
- while($file=readdir($dh)) {
- if ($file=="." || $file=="..") continue; // ignore directory files
-
- /* notice the image source: our PHP thumbnail creator, with
- * the name of the file to create a thumnail for passed in the query string
- */
- print "<td valign=middle><a href='$dirname/$file' target='_blank'><img src='thumbnail.php?file=$dirname/$file' border=0>";
- print "<br>$file</a></td>\n";
- $col++;
-
- // if max number of columns reached, start new row
- if ($col==$num_cols) {
- print "</tr>\n<tr align=center>\n";
- $col=0;
- }
- }
-
- // fill rest of row with empty cells
- for ($i=$col;$i<$num_cols;$i++) {
- print "<td></td>\n";
- }
- ?>
- </tr>
- </table>
-
- </body>
- </html>
-